source('/home/jc148322/scripts/libraries/cool_functions.r')
library(SDMTools)

timeline='Post_decline' # or 'Pre_decline'

wd= paste('/home/jc148322/frog_declines/SDM2/',timeline,'/models/',sep='') #your /models/ directory

species=list.files(wd)
out=NULL
for (spp in species) {
	spp.dir = paste(wd,spp,'/',sep=''); setwd(spp.dir) #set the working directory to the species directory
		
	var.dirs=list.files(spp.dir)
	var.dirs=grep('bioclim',var.dirs,value=TRUE)
	var.dirs=var.dirs[rev(order(sapply(strsplit(var.dirs,'\\.'),length)))] #reorder by decreasing model complexity
	
	out=NULL
	#cycle through each of the species
	for (v in var.dirs) { cat(v,'\n')
		var.dir=paste(spp.dir,v,'/output/',sep='');setwd(var.dir)
	
		auc=read.csv('maxentResults.csv',as.is=TRUE)
		auc=auc[1,6]
		out=c(out, auc)
	}
	out=cbind(var.dirs,out)
	colnames(out)=c('variables','AUC values')
	
	setwd(spp.dir)
	write.csv(out,'AUC_values.csv',row.names=FALSE)
}

